package com.lanyou.esb.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;

/**
 * @author 陈龙涛
 *
 */

@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_ESB_BU_NODE_CLUSTER")
public class ClusterNode {

	private String id;	//节点集群化管理表ID
	
	private String name;	//节点名称

	private String ipaddr;	//IP地址

	private int port;	//端口号

	private String remark;	//备注

//	private String isEnable;	//是否可用

	private String creator;	//创建人

	private Date createTime;	//创建时间

	private String modifier;	//最后更新人员

	private Date modifyTime;	//最后更新时间
	
	private String type;
	
	@Transient
	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}

	public final static Specification<ClusterNode> EmptySpecification = new Specification<ClusterNode>() {
	
		@Override
		public Predicate toPredicate(Root<ClusterNode> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
			// TODO Auto-generated method stub
			return null;
		}
	};
	
	public static Specification<ClusterNode> idSpecification(String id){
		return new Specification<ClusterNode>() {

			@Override
			public Predicate toPredicate(Root<ClusterNode> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				// TODO Auto-generated method stub
				query.where(cb.equal(root.get("id"), id));
				return null;
			}
		};
		
	}
	

	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "NODE_CLUSTER_ID", length = 36)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "NODE_NAME", length = 50)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "IP_ADDRESS", length = 50)
	public String getIpaddr() {
		return ipaddr;
	}
	public void setIpaddr(String ipaddr) {
		this.ipaddr = ipaddr;
	}

	@Column(name = "SERVER_PORT")
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}

	@Column(name = "REMARK", length = 100)
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}

//	@Column(name = "IS_ENABLE", length = 2)
//	public String getIsEnable() {
//		return isEnable;
//	}
//	public void setIsEnable(String isEnable) {
//		this.isEnable = isEnable;
//	}

	@CreatedBy
	@Column(length = 50, updatable = false)
	public String getCreator() {
		return creator;
	}
	public void setCreator(String creator) {
		this.creator = creator;
	}

	@Column(name = "CREATED_DATE", updatable = false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}
	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

}
